Fix memory allocation bug via Issue #118