Made sure ec is destroyed in a finally statement, based on github pull request 4 from Paul Z. X.; also improved error handling for FopServlet