fixed minor bugs, added endian awareness