massive restructure of code