Updating some code fixing bugs, and adding new