added third solution, more concise