big code refactor