added more checking for proper linkage of key