My version 2. Made some modifications.