first pass refactor
working properly with factors
clean up logging and dead code