Renamed tbuf to buf in create_mask() to avoid confusion.