Order imports alphabetically
Name methods consistently
Factor out list comprehension

It led to repetition of code, as we need to perform multiple tasks on
the data.
Create helper "write" method
Add missing docstrings
Simplify import
Clean up syntax and naming