Refactor better jump into another function.
Add a log function to control logging or not logging easily.