Fixed bug with API function