Minor fixes and perf improvements