Handle secondary alignments

I'd like to do some more regression testing before this goes live, but I'm issuing the pull request now so that somebody with more Java experience that me can review the code.