Extracted Alignment code to its own function