Refactored new code and tested agaist a few cases.