Correcting API usage and allocation, memleaks should be reduced.