refactor of error-messages of allocating memory