Cleanup code and fix doctests for py.test
also now should work in travis-ci