Fixed bugs exposed in previous commits