Updated with semi-working code