Large Refactor, fixes