fixed errors and added tests