Add filehandler and fix bug