Move close cursor generation out to a method