Updated the setup function and fixed some bugs