refactored @ancosen PR