Greatly simplified code.