implement rate limiting and write tests

broke tests in process, so probably build will fail