some major code improvements