Extracted entity handle bounds checking into a function