Refatored the free-text APIs code