some code reorganisation