Fixed coding typos and logic errors.