Restructure code and move functionality into functions/modules to enable unit testing. Adding some tests would probably also be a good idea!