Minor refactoring and added script support.