moved nested function