Improved key storing functionality