Algorithm part done. It complains 'too deeply nested'. Don't worry about it.