fix bugs and formting