Did some refactoring

Still need some more work