copied code over from extension
fixed some long lines for pep8