Made changes asked in review by Ramiro Morales.

- Revamped conditional branches with python2 and python3.
- Removed \r and \r\n line endings.
- Moved "import io" to the top.