reworked and renamed most of the stuff so that it allows for easier optimisation