heap realloc fix
better exception handling