Refactor; kudos to Chris Morgan