Fixed memory safety issue