Thanks @aserebrenik for pointing out the range check for < 0