remove redundant code and some fixes