Fixed possible overflows