complete algorithm will handle test case, finished testing given refactoring