Reorganized code

Each file deals with one thing now, rather than many
Definition and implementation are better separated