added extra padding to r in _get_spec, and better exception handling