Made code more efficient and Format changes