code reduce, some fixes