Refactored using a stacked vector as input