call function and do some refactoring