Refactored towards best practices