Refactoring, thanks to @swissmanu