Added API, refactored a bit more