fixing valgrind warning
removing unnecessary scope block
adding new algorithm for cache balancing
removing extraneous includes
fixing for code review comments