Clean up bills code and add some tests