implemented unique constraint check and fixed several validation bugs