some improvements, but a rewrite is incomiiiingg!