Big code refactor