Add error checking for keyfile
Updated several files