Cleaned code, now using Python JSON module and dictionaries instead of directly writing into the file