refactored code

The code have been refactored for improve legibility of the API.