Refactored and reworked