refactored filehandler