Refactor if-then statements and table creation steps to improve legibility.