Flog

Simplify and tidy code, finding problematic areas with https://github.com/seattlerb/flog