Made the serve file function better and added the thread validation to
main.