Fix bugs and tweak