Revert "Revert "Bug fixes:""

This reverts commit cb20b72aaf4cab484b02df6d3103d8267a4ee1f1.