Splitting functionality into files and reducing code complexity