Added an old ReferenceCounter test.
Cleaned code.
Removed ref count decrease causing error.
Cleaned code.
Adapted test to changes.