hacked version to fix #5