copied changes from last bug fixing