Complete rewrite - converted to oldschool