regions should be reversed, and fixes get_end function