Cleanup of code

Cleaned up code, made code more modular