Refactored previous version