make the code base smaller + fix history loop bug