Changed scanning order

Fixed #951