Added primary key test and fixed bugs.