lots of small fixes, many thanks to @asm89