recoded csv input function, recoded csv and json writing functions, cleaned up code.