changed to list, added optimizations