Utilize NAN, fix memory leaks, fix safety issue