added before_open event - closes #626, closes #481