Fix bugs and formating