Add proper bounds checking for blocks