improve solution with math