Fix bugs and improvement