fix a few bugs, remove unused stuff