Fixed errors and added tests