corrected formatting and used slice to copy to buffer