first pass code tidy