Add tests for edge cases, fix Py2.x