Fixed code based on community suggestions.