semi-working code