Fix NullPointerException
LibraryService NullPointerException prevention

Improves cursor closing