Remove unnecessary lines
Move function definitions to top