refactor method (much shorter)
more explicit comparisons and early bailout
refactor out unecessary code