fixed recursive loop