removed some unnecesary code. renamed some functions