a prelimenary implementation using cursors