Refactoring and struct support

initial struct support, some more refactoring, lots more todo.