Added API class
Refactor errors