VID-2044 a bunch of code cleanup