Fix up a bunch of small formatting issues, edge-cases, problems - as pointed out in an internal code review at silverorange