threaded key determining function
& fixed outofbounds exception