refactored code and fixed discrepency between live code and test code implementation