Move functions on top level and make all of them internal
Add unit tests for reversing file