Revert "Removed unnecessary referencing"

This reverts commit 3f0ae8c8be7dbb143533728fb9747888e3b20741.
Revert "Fixed memory leak"

This reverts commit cdc223e6eb52452a26ad29534faee6648936922d.