Main part of code for alignment, but not plugged in yet