Fix bugs and add give up function