Reorganized the code

Reorganized the code to clean things up a little bit