More bug fixes from previous commit