First solution.
Corrected first solution