some cleanup work on formatting and order of operations