Send JSON error responses

Also improve the max items functionality for users.