Fixed memory leak and binding issues