Tidy up formatting; simplify logic