Updated code after bug fixing and test case passing