Refactored some functions and improved line break handling using isWrapBreak flag.