tided up code