Refactored a lot of code, added json functionality and rewrote some stuff