works, but far from perfect...