corrections to code logic