initial revision of the refactoring and cursor guard
using the CursorGuard class