minor refactor, correct logic