Added a few test cases and modified some logic code