Re-Factored with deepak sir ... to be finalized and test cases to be updated