Updated code to reflect @lukearno 's sugegstions