Bug fixes from previous commit