Reworked a lot of code to bring more automation