Refactored
Prepared for final