Implement atomic ops and ref abstract class.

TODO: Use ref to implement connection remove.