fixed main for external call