Implement Attach and Detach
Fix a bug in Attach()
Implement heap sorting