fixing keylength bug at the right place: