moved things around, added some comments, improved tests