fixed potential bugs in fit(...) method