added script params reading, some refactoring