Reference Counting

Added reference counting to allow for more complex objects to be used.