use std::abs instead of hand-rolled substitute
leave early to reduce scope nesting