Do some bounds checking to prevent errors