fix some bugs, which is the the result from crashing in release mode. Mainly, some paths of some function didn't have a return statement.