refactoring to use Rational numbers