Several patches for type inconsistencies and a lock imbalance.