Finish refactor and make it almost workable for mobile(except a json problem)