refactored lcs general functions