Structure studies of neutron-rich beryllium and carbon isotopes