updated prog12

fixed several logic errors