Code restructuring

- Moved all function declarations to a block near start of code
- Made spacing for if and for statements consistent