Internal structure clean-up

Because of a planless attempt of software desing the API does not match
up with the internal implemenetation. This is now undergoing fixes.