fixing a bug in my initial attempt