Complete function code