refactor and rename function findElement