Solution with all tests passing