Bug fixes introduced by code cleanup