Refactoring

Some code refactoring:
1) removed all global variables;
2) change code structure: classes moved to start of script, functions moved to Crudini class.