working ugly code