added second solution and removed reduntant object creation in first solution.