Thread Shed -How can I improve?

I managed to finish the task but I feel the coding is quite bad. Appreciate comments and criticism.
Thank you