Slight refactoring of code