Massive update and refactor