finally got IO working properly