some changes, but some desperate refactoring of code necessary. trying to add in insertions