using a dictionary here would make this code much neater.