Added TODO. corrected resource leakage
Reformatted code.