factorized the code, now Node class has a separate java file.