synced with hermes
fixed memory leaks