My attempt. Passes the tests.