several fixes for managing multiple keys