Restructuring to fix issues