changed second if condition to else