fixed recursive functions