minimization fixes, refactor