Fix build errors,
add generic isempty,
reformat code