Dynamics of k-essence