workingn version for global alignment