done issue #22; fixed some possible bugs