I made a few modifications to reduce logic and made it easier for the python code to replace things