Code corrected as mentioned in comments