fixed bug and typo in var names  and added tests