Use function to access element
Refactoring based on comments