Updated based on fanatoly's suggestions
Updated based on fanatoly's suggestions