cleanup and add some tests