Fix for detached illegalstateexception