attempt at refactoring some cursor code