Various minor improvements in style, error handling and docs