add interrupt handling(not finished, not tested)