copy helper from fog-core