Major refactor

various