modified to allow custom callbacks and switching attributes