Fixed major bug and made a lot of code changes