endian part changed/refactored & tests fixed