Fixed to be more memmory-efficient