modified with my answer to the problem