added part of pointer based implementation