Fixed Bug when calculating max-k