move non-function variable declarations to the top
tweaks
make functions non-anonymous