JBIDE-15168 and some refactoring