Refactored with dictionary code