fix two logical bugs