rework big parts of the code