Changed functions slightly