Refactoring and using SQL corrleation table