Refactoring

Fixed as many JSHint errors as I could, mainly to stop declaring
functions inside other functions before they were declared as functions.
Yo dawg.