improved javascript for alignment