Refactored code for Java 7 compatibility #3