BeginFunction bug fixed