Add file related functions and test