final code cleanup before total rewrite