RIM reports loss but beats expectations