replaced code with function and changed function name