got IO to work correctly, needs to be cleaned up though