changing elements accessed with [] and some refactoring