fix erorrs and add tests