fixed errors, added some tests