removed redundant code and other bug fixes