beginning of java implementation and python implementation