Slightly refactored