Tidy up code and implement better variables