fixed foldr and added reverse