Modified as per TD's suggestions