On the replica method for glassy systems