Refactoring based on @oza's comments