refactor line ordering logically