Add guard + a bit of refactoring