Fix bugs and fix #34