Started refactoring as suggested by Earnestly