refactored to make it better