VID-849 Move some code around to more logical places