Add ability to customize attach and detach code