move calc_alignment to global scope