Final commit

Refactored some code