Fixed code according to Arnaud's comments