Code cleanup and refactoring. Fix JBoss support.