Added value_tests and fixed reference counter handling