Fixed logic error with pending orders

Fixed logic error with pending orders