code cleanup, optimizations hw4