Use constants instead of magic numbers, fix up formatting