Made the code more robust in the library servlet