fixing some nested if problems