Simplified code and minor changes.