sligtly less ugly function