fixed input, added and renamed some functions