bugs fixed at let in function