fixing overflow detection