modified slightly for part 2