moved code to java 8
fixed casting
migrated to java 8