fixed bug in using factor variables