code cleanup, performance optimization