Refactor into single function
Refactor into single function