fixed scope bugs