code implemented for ex6 -- just debugging (unit test not passing)