Fixed Leak and cleaned code