was getting the right result added a new variable and changed else if