use vector rather than malloc