Fixed hoisting bug and TS compilation issue