Fixed detach and added some new functions