improved comments and error detection