Added an application directory and converted some parts of the main function to applications