calls to malloc now error-checking