cleanup code and handle error cases

if a block does not return any content, += caused an exceptions resulting in a white screen