code basically done, small error in the result.