added the logic in api