script fixes and cleanup