did some cleanup, added some tests