Tidying up on main section of code