removed unnecessary state transition and redid some logic