long overdue fix. this needs a rewrite anyway