Reordered, added ending varible