add comments
error handling and memory management