improved implementation of select and delete