fix bugs and make it stable