first draft of reference counting functions
more improvements with regards to dereferencing