Fixed bug in rem()