Changed event registration so it can be cleaned up properly
Added cleanup function to doc so it can be cleaned up properly