took steps towards making the code less spaghetti.