fixed bug with last byte, added tests