Added more unit tests and fixed wrong increment of refcount for fname