Upgraded to handle different environments.
Test cases mostly filled. Still a handfull of tough cases. Bypassed them xit().