fixed some boolean logic and clarified the intent in comments
refactored to static method
Merge pull request #144 from wanderingbort/fixing-precedence-bug

Fixing precedence bug