refactoring scripts; fix bug #4 and #1.#2 partly