Add alignment support.

And fix some bugs.