fixed minor bugs and added some tests