fixed indentation and writing to file