added a function to reset the key
added functions to eliminate unneccesary code