Fixed some minor leaks and an another issue when deleting