fixed some errors and added tests