recreated vec function
efficiency optimization in solution