Clean up script code majorly