Fixing quite a few bugs and adding a script