More maintainable memory handling.

Remove unnecessary casts from (void *).
Give expression to sizeof operator.
These changes make the code less prone to bugs by removing
repetition of type names in multiple places.
More consistent comment style.