now with tests, which are hacky as hell