Refactored script to allow gradual testing