refactoring and extracting some functional to separate functions