Proofed for redundancy and removed unecessary extra switch case
Updated version for minor optimization