Fixed generateKey() exceptions, added more debug