why does this work for retrieving code but not as script