first pass cleanup and bug fix for local