Fixed code based on Java 8