Bug fixes from last commit