Replaced doubles by Reals, fixed two bugs