Refactoring as suggested by kajic