Some code refactoring for better reading and understanding.