changes from dans code merged