Refactoring, extract some code to be reusable from utils class