This version sort of works, but needs much improvement