added diagnostic info for 500 errors
comments
input checking using testthat