added Mihai's shape alignment code