add error check to swap buffer