fixed bug whereby elemp wasn't initialized for each iteration