refactoring on my taste
vars and functions allocation, basic indexes