added global variable to count rectangles created
count instances refactoring