fix bugs and beautify