fix a few bugs, maintain key sizes