Fixed logic issue