Added error check loop, incorrect compared to test case