code cleanup, optimization