Fix a few bugs related to #623