Added assertions and more descriptive comments

Added assertions to check if malloc was returning a null pointer.
Updated and added header comments for supporting methods.