Some slight refactoring to streamline the code