fixing some functions and cleaning up