a set of cleanup and bug fixes