Fixes a nasty stack corruption issue and a big endian fix. Signed-off-by: Rosen Penev <rosenp@gmail.com>