refactor and implement io module