starting attempt to make this function faster