general cleanup and refactor