fixed leak and added leak test