cleaning up. renamed and moved functions