Refactoring, NPE fixed. #123