manually merged some changes from jeremy