Rearranged code to better group toolbox code and non-toolbox code