big mess, rewrite needed