Submission 2. Updated and optimized.