Simplify config and make functions more generic