inline doc, fix echo function bug
add more documentation inline with code and cleanup code