Bug fixes
Some script cleanup