not stupid way of doing bounds checking