Refactors element position calculations into a function
and makes previous and next arrow positions more dynamic