add some print statements, fixed scoping issue