Implemented link. Implemented reference counting and resource freeing for all resources. Fixed small bug in tests.