refactoring & fixed reading variable