Moved all functions to bottom

under all main code