plenty of refactoring, couple bugs fixed,tested with wildfly 9