changed constant from K to KMAX