Move malloc implementation to separate file