some optimizations (final)