Made the solution more generic