write logic for optimizeArguments and isSafe