Added in error handling for setting up key. Minor changes.