Move f to top let

Just a simple refactoring.