Refactor the worst part