Tidy Up

Removed useless code and changed chuck of code to funtion