ported code from billpanel