Some working code

May need some polish. Maybe.