fixed code to use variables defined, and prevented a seires os static analyzer warnings