moved file handler to own file. Added some doc and simplified a bit of code