Greatly simplified code