better error checking and some style fixes in the program script