Cleaned

Cleaning up the code. Bringing some structure to it.