Some small refactorings. Still getting the AccessViolation sometimes.