code cleanup and moved class functions to own file