cleanup and bug fixes from a while ago