Attaching and detaching events

This just adds an attaching event and detaching events that are triggered before attach and detach execute.