Another version of library management

This has all the logic in db