Fixed some bugs

Also added some additions to code