fixed bug in handling of ref tag in Java, added handling in Python