CODE: code restructuring

* heavy use of the exposed functions instead of accessing
  directly to the data structures