First solution attempt (including comments)