build fix and remove premature optimization and kill mallocs