Added settings and improved code