Fix some bugs in the setup function