Pretty major changes to the code, implemented a few new functions