tidying
added file exists check