updated script so it can be run on non-X environment, corrected output if API key is not set