Moved code around to make adding more applications easier and more module