Made more universal. See comments.