Fix bugs to make it work