fix scope bugs