Some tweaking of 4 year old code