I managed to break down the many cases into a switch-case monster. The blank cases still needs to be filled in. Once that is done, the whole thing needs to be tested out properly, because there are way too many cases where something could go wrong.
Screenshot