Consolidate code that checks if a pos lies within a range