optimize io handling
little refactoring
implement gen_server