Changed input parameters format.
Refactored.
Improved error handling.