Some bugs fixed, several malloc() removed