Fixed pep8 issues.
Moved code that determines whether the memory initialization is necessary to a function that ensures the code is only executed once.