working ugly solution IO