use size_t for sizes
refactor the code and handle cnames