reordered some code, to make it more pretty