Refactor library dataset code into a common superclass