Fix for #78

Bug for for #78 and other bugs found when increasing test coverage; minor refactoring of alignment internals to improve code readability