fixed readVal stack error by implementing a local variable