Added checkroot and put script into functions