huge file refactor