Simplified in more functional style