Merge pull request #4600 from jbclements/cleanup-and-test-cases

cleaning up, adding tests
fix trailing whitepace