Fixed mod for negative denominators, removed some extra unused code