Fixed bytewise I/O and changed to bitwise