final solution
fixed regression in stack order