reapply bug fixes from nextgen branch
continue to sync up with original nextgen changes