add APIKEY support + fix bug in main