ENH: added tests, some reorganization