Quantum heat engines and refrigerators