Fix bugs, some cleanups