refactoring based on Liam M's suggestions.