Slight code refactoring and simplification, as suggested by @wolever