Refactored sample a bit for better comprehensibility