Reformatted code and added in orientation constraint.