added some tests, did some rewriting