move python logic to java