Some fixes to bugs @bnmnetp found