Refactor, update for mysql

pep8 and mysql (tested, but not extensively; and not on non-mysql)