patched to make it work