implemented for Python and Java