refactored position checking into individual functions.