Fixed implementation, it now works correctly for seemingly every number except for 2,000,000