Working version with API