Refactored to add more features.