added safe_vector; made a few tweaks