Basic refactoring for newer version of java
Fixed integer overflow bug