Added directory exists check to surf function