A hacky functional version working