First working (non-optimal) solution