Refactored the logic, plus some of the margins