minor error handling re-added