minor fixes, comments added, possible memory allocation error found and fixed