fix a recursion issue. should use 'if' rather than 'else if "