Fix formats, redundant imports, shadowing, etc

This commit makes hlint and ghc -Wall -Werror rather more happy. Still
quite a bit to do w.r.t. to code structure though.