Removes unused imports
Gets rid of a level of indentation
Moves var to location it is used
Removes redundant def
Simplifies if condition (and some :fish:)