finished cfg implementation