Restructuring some code

Tidy up