refactored as suggested by Stefan