fixing some issues discovered when testing Rahul's script