Why elem is defined outside?