first version of scalar_replace by Beyhan Veliev