Fix box pattern matching and use borrowing operator