Program working; tidying up code