Do some checking to prevent overflows