Lagrangian systems in the presence of singularities