Revert "Bug fixes and minor updates"

This reverts commit 7e195f6507a7b2f1b8d9da32e2048f259903f35c.
Revert "Revert "Bug fixes and minor updates""

This reverts commit 8369de38268103c2587320fee24cc8821f3ed08c.