Rearranged code

Moved around the constants and variable declarations to more logical and
clear positions. Anything that might need to be adjusted is now at the
top.