fixing some logic errors with #631