Seperated the script into different methods, although I'm not sure it was appropriately split up.