Simplified by removing local variables