address comments and fix some additional bugs