Refactor the ugly