Added check for correct length of key