Fix missing include
Add missing error handling to lib