Revert "Revert "Fix all bugs""

This reverts commit 6e0c33523b7239222030e9b31beac466f7345ac7.