Refactored to gain flexibility