5 reworked with optimizations