ENH+STY: Speed up bound checking, cleanup code