Revert "Fixed misc bugs"

This reverts commit 6406647e9bc9f08a579f3d96ed63e310e33d3be2.
Revert "Revert "Fixed misc bugs""

This reverts commit 19e4988d003280f34aa440314f2858f6edb84c3d.