fixed test cases and small fix to code