Fixed comparison and writing. Now works as intended I believe.
Update helping comments.