Big upgrade and refactor