Refactored version 2