Revert "Some bug fixes"

This reverts commit 215e598a36ba0c4bc0491c69e93a5da57de68803.