added numkeys sanity check and implemented print