Made domain configurable; improved error handling