Some cleanup and formatting as well as renaming variables should be done in order to make the code look more unified.