Refactored some code. Tried to increase decoupling.