fixed args logic error and minor refactoring