Simplified code and more comments