some general cleanup and refactor