Code refactorization and minor adjustments.