error codes handling, malloc wrapper added; small changes