apply rules of threes in reverse: inline some logic which isn't very complicated and is only called twice
rename some variables