more refactoring and attempt to merge desktop and controller code