converted some parts to java