fix #624 and #799, better error messages and style