reordered functions in app js to follow execution flow