Some code reorganisation, more comments