reorganize, add some tests