Removing unused function, adding check if variable exists