code cleanup, performance improvements