first and last byte bug fixed