bug fixes. some cleanups