code improvements

one bug still to be fixed