working out how to modify values outside of nested functions