This function is really confusing... It's not very clear to me but I think that what Bart suggests works.