Bug fixes + refactorings.