improve doc, cleanup code