Fix some bugs in loader