Minor optimizations

- Cache getClass results
- Remove additional forEach definition
- Remove property access before try-catch