Refactor the long and stupid code.