simplified somewhat