Added if __name__ conditions to run files. This stops horrible horrible things happening when trying to run tests.
Refactored structure of module.