Fixed memory leak and added span click handling