Fix bugs, cleanup