factored out a few things into a util module, and fixed some indenting