enhance to work with perfect-margin mode for better display experience