Fix critical bugs

Fix critical bugs.