add some tests and cleanup code a bit