misc bugfixes, cleanup, etc...