nicer solution for bounds checking