Refactored based on @FelixGV comment