Refactor/more checks

* Aligned assignments
* Added more checks (empty files, prevent writing)