More cleanup, fix bugs