Added onBeforeOpen callback