based on mengxr's suggestions