Code slightly refactored