Fixed dangling pointer error